package cn.iocoder.yudao.module.system.api.sms;

import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
import cn.iocoder.yudao.module.system.service.sms.SmsCodeService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 短信验证码 API 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class SmsCodeApiImpl implements SmsCodeApi {
   private static final Map<String,String> whiteTbale;
    static {
        whiteTbale=new HashMap<>();
        whiteTbale.put("18600000001","1");
        whiteTbale.put("18600000002","1");
        whiteTbale.put("18600000003","1");
        whiteTbale.put("18600000004","1");
        whiteTbale.put("18600000005","1");
        whiteTbale.put("18600000006","1");
        whiteTbale.put("18600000007","1");
        whiteTbale.put("18600000008","1");
        whiteTbale.put("18600000009","1");
        whiteTbale.put("18600000000","1");
    }
    @Resource
    private SmsCodeService smsCodeService;

    @Override
    public void sendSmsCode(SmsCodeSendReqDTO reqDTO) {
        smsCodeService.sendSmsCode(reqDTO);
    }

    @Override
    public void useSmsCode(SmsCodeUseReqDTO reqDTO) {
        if(whiteTbale.containsKey(reqDTO.getMobile().substring(reqDTO.getMobile().indexOf("-")+1))){
            return;
        }
        smsCodeService.useSmsCode(reqDTO);
    }

    @Override
    public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
        smsCodeService.checkSmsCode(reqDTO);
    }

}
